export default {
  // div拖动函数
  moveDivBox (e,element) {
    // let odiv = e.target; //获取目标元素
    e.stopPropagation()
    e.stopImmediatePropagation()
    const odiv = document.getElementById(element) || document.getElementsByClassName(element)[0];
    // 算出鼠标相对元素的位置
    const disX = e.clientX - odiv.offsetLeft
    const disY = e.clientY - odiv.offsetTop
    document.onmousemove = e => {
      // 鼠标按下并移动的事件
      // 用鼠标的位置减去鼠标相对元素的位置，得到元素的位置
      const left = e.clientX - disX
      const top = e.clientY - disY

      // 绑定元素位置到positionX和positionY上面
      this.positionX = top
      this.positionY = left

      // 移动当前元素
      odiv.style.position = 'absolute'
      odiv.style.left = left + 'px'
      odiv.style.top = top + 'px'
    }
    document.onmouseup = e => {
      document.onmousemove = null
      document.onmouseup = null
    }
  },
	//检查年月信息
  checkYearMonth (ymParam){
		if(undefined !== ymParam && null !== ymParam){
			return true;
		}
		return false;
	},
  // /**
  //  * 根据开始报告期 结束报告期 获得报告期列表
  //  * @param startYear 开始年(int)
  //  * @param startMonth 开始月(int)
  //  * @param endYear 结束年(int)
  //  * @param endMonth 结束月(int)
  //  * @param maxMonth 月最大值(int)
  //  * @param minMonth 月最小值(int)
  //  * @param type 报告期类型(int)
  //  * @return
  //  */
  getPeriod(startYear, startMonth, endYear, endMonth, maxMonth, minMonth, type) {
    var periodVos = [];
    for (var i = startYear; i <= endYear; i++) {
      if (i == startYear) {
        var temp = 0;
        if (startYear === endYear) {
          temp = endMonth;
        } else {
          temp = maxMonth;
        }
        for (var j = parseInt(startMonth); j <= temp; j++) {
          
          var periodVo = {
            "year": i,
            "month": j,
            "type": type,
          }
          periodVos.push(periodVo);
        }
      } else if (i == endYear) {
        for (var j = minMonth; j <= endMonth; j++) {
          var periodVo = {
            "year": i,
            "month": j,
            "type": type,
          }
          periodVos.push(periodVo);
        }
      } else {
        for (var j = minMonth; j <= maxMonth; j++) {
          var periodVo = {
            "year": i,
            "month": j,
            "type": type,
          }
          periodVos.push(periodVo);
        }
      }
    }
    return periodVos;
  },
  // /**
  //    * 根据开始报告期 结束报告期 获得报告期列表
  //    * @param startYear 开始年
  //    * @param startMonth 开始年/月/季/半年
  //    * @param endYear 结束年
  //    * @param endMonth 结束年/月/季/半年
  //    * @param type 报告期类型
  //    * @return
  //    */
  getPeriodByStartEnd(startYear, startMonth, endYear, endMonth, type) {
    var periodVos = [];
    if (this.checkYearMonth(startYear) && this.checkYearMonth(startMonth) && this.checkYearMonth(endYear) && this.checkYearMonth(endMonth)) {
      var maxMonth = 0;
      var minMonth = 0;
      switch (type) {
        case 1: //年报
          maxMonth = 0;
          minMonth = 0;
          periodVos = this.getPeriod(startYear, startMonth, endYear, endMonth, maxMonth, minMonth, type);
          break;
        case 2: //月报
          maxMonth = 12;
          minMonth = 1;
          periodVos = this.getPeriod(startYear, startMonth, endYear, endMonth, maxMonth, minMonth, type);
          break;
        case 32:  //季报 2 5 8 11
          maxMonth = 4;
          minMonth = 1;
          periodVos = this.getPeriod(startYear, startMonth, endYear, endMonth, maxMonth, minMonth, type);
          break;
        case 33:  //季报 3 6 9 12
          maxMonth = 4;
          minMonth = 1;
          periodVos = this.getPeriod(startYear, startMonth, endYear, endMonth, maxMonth, minMonth, type);
          break;
        case 4:  //半年报
          maxMonth = 2;
          minMonth = 1;
          periodVos = this.getPeriod(startYear, startMonth, endYear, endMonth, maxMonth, minMonth, type);
          break;
        default:
          console.log("报告期类型错误");
      }
    } else {
      console.log("获取报告期信息错误");
      return;
    }
    return periodVos;
  }
};
